use fltk::{prelude::*, *};

fn main() {
    let a: app::App = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut win = window::Window::default().with_size(800, 600);
    let mut row = group::Flex::default_fill().row();
    main_panel(&mut row);
    row.end();
    win.resizable(&row);
    win.set_color(enums::Color::from_rgb(250, 250, 250));
    win.end();
    win.show();
    win.size_range(600, 400, 0, 0);
    a.run().unwrap();
}


fn login_panel(parent:&mut group::Flex){

    let mut urow = group::Flex::default().row();
    {
        frame::Frame::default();
        let username = input::Input::default().with_label("用户");
        urow.fixed(&username, 150);
        urow.end();
    }

    let mut prow = group::Flex::default().row();
    {
        frame::Frame::default();
        let password = input::SecretInput::default().with_label("密码");
        prow.fixed(&password, 150);
        prow.end();
    }

    let pad: frame::Frame = frame::Frame::default();

    let mut brow: group::Flex = group::Flex::default().row().with_align(enums::Align::Center);
    {   
        let f = frame::Frame::default();
        let reg = create_button("登录");

        brow.fixed(&reg, 80);
        brow.end();
    }

    parent.fixed(&urow, 30);
    parent.fixed(&prow, 30);
    parent.fixed(&pad, 1);
    parent.fixed(&brow, 30);

}
fn left_panel(parent: &mut group::Flex) {

    let mut col_login = group::Flex::default().column();
    login_panel(&mut col_login);
    col_login.end();
    parent.fixed(&col_login, 300);
}

fn main_panel(parent: &mut group::Flex) {

    let mut ml = group::Flex::default().column().with_align(enums::Align::Center);
    left_panel(&mut ml);
    ml.end();

    let mr = group::Flex::default().column();
    let mut frame2 = frame::Frame::default();
    frame2.set_frame(enums::FrameType::BorderBox);
    frame2.set_color(enums::Color::from_rgb(200, 0, 0));
    mr.end();

    parent.fixed(&ml, 200);
    parent.add(&mr);
    
}

fn create_button(caption: &str) -> button::Button {
    let mut btn = button::Button::default().with_label(caption);
    btn.set_color(enums::Color::from_rgb(225, 225, 225));
    btn
}
